home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / graphics / flick_1.0 / source / adaptive.s next >
Text File  |  1994-11-17  |  20KB  |  753 lines

  1. ;
  2. ;        Flick FLI-format Animation Viewer v1.0          19 Dec 1993
  3. ;        --------------------------------------
  4. ;
  5. ;
  6. ;This program plays 320x200x8 FLI-format bitmapped animation files on
  7. ;any ECS or AGA Amiga running OS2.04 or higher.  FLI-format files are
  8. ;produced by Autodesk Animator and Autodesk 3D Studio on a PC, as well
  9. ;as by other programs.
  10. ;
  11. ;The files in this archive may be distributed anywhere provided they are
  12. ;unmodified and are not sold for profit.
  13. ;
  14. ;Ownership and copyright of all files remains with the author:
  15. ;
  16. ;    Peter McGavin, 86 Totara Crescent, Lower Hutt, New Zealand.
  17. ;    e-mail: peterm@maths.grace.cri.nz
  18. ;
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;        xdef    _chunky2planar
  21.  
  22.         ifeq    width-320
  23.         xdef    _chunky2planar320x200
  24.         else
  25.         ifeq    width-640
  26.         xdef    _chunky2planar640x480
  27.         endc
  28.         endc
  29.  
  30. ; peterm/adaptive.s
  31. ; Combines peterm/chunky4.s and jmccoull/blitter4pass.s
  32. ; The blitter works on the top portion of the display at the same time as
  33. ; the CPU converts the bottom portion.
  34. ; The blitter has completely finished before the routine returns.
  35. ; Both parts of every call are timed using the EClock.
  36. ; The partition point is recalculated at the end of the call in an attempt
  37. ; to keep the two routines taking about the same amount of time.
  38. ;
  39. ; The following formula is used:
  40. ;
  41. ;    n_blit = n * t_cpu * n_blit / (t_blit * n_cpu + t_cpu * n_blit)
  42. ;
  43. ; where:
  44. ;    n    is the total number of 32-byte units (i.e, width*height/32)
  45. ;    n_blit    is the number of 32-byte units above the partition
  46. ;    n_cpu    is the number of 32-byte units below the partition (=n-n_blit)
  47. ;    t_blit    is the time taken by the blitter in EClock units
  48. ;    t_cpu    is the time taken by the cpu in EClock units
  49. ;
  50. ; ECS Agnus required (for long blits)
  51.  
  52. bltcpt         equ    $048
  53. bltbpt         equ    $04c
  54. bltapt         equ    $050
  55. bltdpt         equ    $054
  56. bltsizv      equ    $05c
  57. bltsizh      equ    $05e
  58. cleanup        equ    $40
  59. _LVOReadEClock    equ    -60
  60.  
  61. ;-----------------------------------------------------------------------------
  62. ; chunky2planar:    (new Motorola syntax)
  63. ;  a0 -> chunky pixels (in FAST RAM)
  64. ;  a1 -> plane0 (assume other 7 planes are allocated contiguously)
  65. ;  a3 -> tmp chip buffer0, size=width*height
  66. ;  a4 -> tmp chip buffer1, size=width*height
  67. ;  a5 = TimerBase
  68. ;  a6 = GfxBase
  69.  
  70. ;width        equ    320        ; must be a multiple of 32
  71. ;height        equ    200
  72. pixels        equ    width*height
  73. plsiz        equ    (width/8)*height
  74.  
  75.  
  76.         section    code,code
  77.  
  78.         ifeq    width-320
  79. _chunky2planar320x200:
  80.         else
  81.         ifeq    width-640
  82. _chunky2planar640x480:
  83.         endc
  84.         endc
  85.  
  86.         movem.l    d2-d7/a2-a6,-(sp)
  87.  
  88. ; save parameters
  89.  
  90.         movea.l    #mybltnode,a2
  91.         move.l    a0,(chunky-mybltnode,a2)
  92.         move.l    a1,(plane0-mybltnode,a2)
  93.         move.l    a3,(buff0-mybltnode,a2)
  94.         move.l    a4,(buff1-mybltnode,a2)
  95.         move.l    a5,(timerbase-mybltnode,a2)
  96.         move.l    a6,(gfxbase-mybltnode,a2)
  97.  
  98. ; copy pixels_blit from chunky to buff0 (from FAST to CHIP) for the blitter
  99.  
  100.         movea.l    (chunky-mybltnode,a2),a0
  101.         movea.l    (buff0-mybltnode,a2),a1
  102.         move.l    (pixels_blit-mybltnode,a2),d0
  103.         movea.l    (4).w,a6
  104.         jsr    (_LVOCopyMemQuick,a6)
  105.  
  106. ; read the start time
  107.  
  108.         lea    (starttime-mybltnode,a2),a0
  109.         movea.l    (timerbase-mybltnode,a2),a6
  110.         jsr    (_LVOReadEClock,a6)
  111.  
  112. ; start the blitter in the background
  113.  
  114.         st    (waitflag-mybltnode,a2)
  115.         movea.l    a2,a1
  116.         movea.l    (gfxbase-mybltnode,a2),a6
  117.         jsr    (_LVOQBlit,a6)
  118.  
  119. ; compute starting parameters for the CPU routine
  120.  
  121.         move.l    #plsiz,d0
  122.         sub.l    (plsiz_blit-mybltnode,a2),d0
  123.         lsr.l    #2,d0
  124.         move.w    d0,-(sp)    ; outer loop counter on stack
  125.  
  126.         move.l    (chunky-mybltnode,a2),a0
  127.         adda.l    (pixels_blit-mybltnode,a2),a0    ; offset into chunky
  128.  
  129.         move.l    (plane0-mybltnode,a2),a1
  130.         adda.l    (plsiz_blit-mybltnode,a2),a1    ; offset into plane
  131.  
  132.         lea    (buffers-mybltnode,a2),a3    ; a3 -> buffers
  133.  
  134.     iflt 4*plsiz-4-32768
  135.         adda.w    #3*plsiz,a1    ; a1 -> plane 3
  136.     else
  137.     iflt 2*plsiz-4-32768
  138.         adda.w    #1*plsiz,a1    ; a1 -> plane 1
  139.     endc
  140.     endc
  141.  
  142. ; set up register constants
  143.  
  144.         move.l    #$0f0f0f0f,d5    ; d5 = constant $0f0f0f0f
  145.         move.l    #$55555555,d6    ; d6 = constant $55555555
  146.         move.l    #$3333cccc,d7    ; d7 = constant $3333cccc
  147.         lea    (4,a3),a2    ; used for inner loop end test
  148.  
  149. ; load up address registers with buffer ptrs
  150.  
  151.         lea    (2*4,a3),a4    ; a4 -> plane2buf
  152.         lea    (2*4,a4),a5    ; a5 -> plane4buf
  153.         lea    (2*4,a5),a6    ; a6 -> plane6buf
  154.  
  155. ; main loop (starts here) processes 8 chunky pixels at a time
  156.  
  157. mainloop:
  158.  
  159. ; d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0
  160.  
  161.         move.l    (a0)+,d0    ; 12 get next 4 chunky pixels in d0
  162.  
  163. ; d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0
  164.  
  165.         move.l    (a0)+,d1    ; 12 get next 4 chunky pixels in d1
  166.  
  167. ; d2 = d0 & 0f0f0f0f
  168. ; d2 = ........a3a2a1a0 ........b3b2b1b0 ........c3c2c1c0 ........d3d2d1d0
  169.  
  170.         move.l    d0,d2        ;  4
  171.         and.l    d5,d2        ;  8 d5=$0f0f0f0f
  172.  
  173. ; d0 ^= d2
  174. ; d0 = a7a6a5a4........ b7b6b5b4........ c7c6c5c4........ d7d6d5d4........
  175.  
  176.         eor.l    d2,d0        ;  8
  177.  
  178. ; d3 = d1 & 0f0f0f0f
  179. ; d3 = ........e3e2e1e0 ........f3f2f1f0 ........g3g2g1g0 ........h3h2h1h0
  180.  
  181.         move.l    d1,d3        ;  4
  182.         and.l    d5,d3        ;  8 d5=$0f0f0f0f
  183.  
  184. ; d1 ^= d3
  185. ; d1 = e7e6e5e4........ f7f6f5f4........ g7g6g5g4........ h7h6h5h4........
  186.  
  187.         eor.l    d3,d1        ;  8
  188.  
  189. ; d2 = (d2 << 4) | d3
  190. ; d2 = a3a2a1a0e3e2e1e0 b3b2b1b0f3f2f1f0 c3c2c1c0g3g2g1g0 d3d2d1d0h3h2h1h0
  191.  
  192.         lsl.l    #4,d2        ; 16
  193.         or.l    d3,d2        ;  8
  194.  
  195. ; d0 = d0 | (d1 >> 4)
  196. ; d0 = a7a6a5a4e7e6e5e4 b7b6b5b4f7f6f5f4 c7c6c5c4g7g6g5g4 d7d6d5d4h7h6h5h4
  197.  
  198.         lsr.l    #4,d1        ; 16
  199.         or.l    d1,d0        ;  8
  200.  
  201. ; d3 = ((d2 & 33330000) << 2) | (swap(d2) & 3333cccc) | ((d2 & 0000cccc) >> 2)
  202. ; d3 = a1a0c1c0e1e0g1g0 b1b0d1d0f1f0h1h0 a3a2c3c2e3e2g3g2 b3b2d3d2f3f2h3h2
  203.  
  204.         move.l    d2,d3        ;  4
  205.         and.l    d7,d3        ;  8 d7=$3333cccc
  206.         move.w    d3,d1        ;  4
  207.         clr.w    d3        ;  4
  208.         lsl.l    #2,d3        ; 12
  209.         lsr.w    #2,d1        ; 10
  210.         or.w    d1,d3        ;  4
  211.         swap    d2        ;  4
  212.         and.l    d7,d2        ;  8 d7=$3333cccc
  213.         or.l    d2,d3        ;  8
  214.  
  215. ; d1 = ((d0 & 33330000) << 2) | (swap(d0) & 3333cccc) | ((d0 & 0000cccc) >> 2)
  216. ; d1 = a5a4c5c4e5e4g5g4 b5b4d5d4f5f4h5h4 a7a6c7c6e7e6g7g6 b7b6d7d6f7f6h7h6
  217.  
  218.         move.l    d0,d1        ;  4
  219.         and.l    d7,d1        ;  8 d7=$3333cccc
  220.         move.w    d1,d2        ;  4
  221.         clr.w    d1        ;  4
  222.         lsl.l    #2,d1        ; 12
  223.         lsr.w    #2,d2        ; 10
  224.         or.w    d2,d1        ;  4
  225.         swap    d0        ;  4
  226.         and.l    d7,d0        ;  8 d7=$3333cccc
  227.         or.l    d0,d1        ;  8
  228.  
  229. ; d2 = d1 >> 7
  230. ; d2 = ..............a5 a4c5c4e5e4g5g4b5 b4d5d4f5f4h5h4a7 a6c7c6e7e6g7g6..
  231.  
  232.         move.l    d1,d2        ;  4
  233.         lsr.l    #7,d2        ; 22
  234.  
  235. ; d0 = d1 & 55555555
  236. ; d0 = ..a4..c4..e4..g4 ..b4..d4..f4..h4 ..a6..c6..e6..g6 ..b6..d6..f6..h6
  237.  
  238.         move.l    d1,d0        ;  4
  239.         and.l    d6,d0        ;  8 d6=$55555555
  240.  
  241. ; d1 ^= d0
  242. ; d1 = a5..c5..e5..g5.. b5..d5..f5..h5.. a7..c7..e7..g7.. b7..d7..f7..h7..
  243.  
  244.         eor.l    d0,d1        ;  8
  245.  
  246. ; d4 = d2 & 55555555
  247. ; d4 = ..............a5 ..c5..e5..g5..b5 ..d5..f5..h5..a7 ..c7..e7..g7....
  248.  
  249.         move.l    d2,d4        ;  4
  250.         and.l    d6,d4        ;  8 d6=$55555555
  251.  
  252. ; d2 ^= d4
  253. ; d2 = ................ a4..c4..e4..g4.. b4..d4..f4..h4.. a6..c6..e6..g6..
  254.  
  255.         eor.l    d4,d2        ;  8
  256.  
  257. ; d1 = (d1 | d4) >> 1
  258. ; d1 = ................ a5b5c5d5e5f5g5h5 ................ a7b7c7d7e7f7g7h7
  259.  
  260.         or.l    d4,d1        ;  8
  261.         lsr.l    #1,d1        ; 10
  262.  
  263.         move.b    d1,(4,a6)    ; 12 plane 7
  264.         swap    d1        ;  4
  265.         move.b    d1,(4,a5)    ; 12 plane 5
  266.  
  267. ; d2 |= d0
  268. ; d2 = ................ a4b4c4d4e4f4g4h4 ................ a6b6c6d6e6f6g6h6
  269.  
  270.         or.l    d0,d2        ;  8
  271.  
  272.         move.b    d2,(a6)+    ;  8 plane 6
  273.         swap    d2        ;  4
  274.         move.b    d2,(a5)+    ;  8 plane 4
  275.  
  276. ; d2 = d3 >> 7
  277. ; d2 = ..............a1 a0c1c0e1e0g1g0b1 b0d1d0f1f0h1h0a3 a2c3c2e3e2g3g2..
  278.  
  279.         move.l    d3,d2        ;  4
  280.         lsr.l    #7,d2        ; 22
  281.  
  282. ; d0 = d3 & 55555555
  283. ; d0 = ..a0..c0..e0..g0 ..b0..d0..f0..h0 ..a2..c2..e2..g2 ..b2..d2..f2..h2
  284.  
  285.         move.l    d3,d0        ;  4
  286.         and.l    d6,d0        ;  8 d6=$55555555
  287.  
  288. ; d3 ^= d0
  289. ; d3 = a1..c1..e1..g1.. b1..d1..f1..h1.. a3..c3..e3..g3.. b3..d3..f3..h3..
  290.  
  291.         eor.l    d0,d3        ;  8
  292.  
  293. ; d4 = d2 & 55555555
  294. ; d4 = ..............a1 ..c1..e1..g1..b1 ..d1..f1..h1..a3 ..c3..e3..g3....
  295.  
  296.         move.l    d2,d4        ;  4
  297.         and.l    d6,d4        ;  8 d6=$55555555
  298.  
  299. ; d2 ^= d4
  300. ; d2 = ................ a0..c0..e0..g0.. b0..d0..f0..h0.. a2..c2..e2..g2..
  301.  
  302.         eor.l    d4,d2        ;  8
  303.  
  304. ; d3 = (d3 | d4) >> 1
  305. ; d3 = ................ a1b1c1d1e1f1g1h1 ................ a3b3c3d3e3f3g3h3
  306.  
  307.         or.l    d4,d3        ;  8
  308.         lsr.l    #1,d3        ; 10
  309.  
  310.         move.b    d3,(4,a4)    ; 12 plane 3
  311.         swap    d3        ;  4
  312.         move.b    d3,(4,a3)    ; 12 plane 1
  313.  
  314. ; d2 = d2 | d0
  315. ; d2 = ................ a0b0c0d0e0f0g0h0 ................ a2b2c2d2e2f2g2h2
  316.  
  317.         or.l    d0,d2        ;  8
  318.  
  319.         move.b    d2,(a4)+    ;  8 plane 2
  320.         swap    d2        ;  4
  321.         move.b    d2,(a3)+    ;  8 plane 0
  322.  
  323. ; te